﻿package bdz.projects.lavender.cms.model
{
	
	/**
	 * ...
	 * @author ...
	 */
	public class DataModel extends ObjectBase
	{
		
		
		private static var instance:DataModel;
		private var _sessionid:String;
		
		function DataModel(se:SingletonEnforcer, xlist:XML) {
			super(xlist);
		}
		public static function getModel(xlist:XML = null):DataModel {
			
			if (!instance) {
				instance = new DataModel(new SingletonEnforcer(), xlist);
			}
			return instance;
		}
		public function getObjectWithName(nme:String):ObjectBase{
			for each(var cont:ContainerData in _containers){
				if(cont.name == nme){
					return cont;
				}
			}
			for each(var obj:ObjectData in _objects){
				if(obj.name == nme){
					return obj;
				}
			}
			return null;
		}
		private function getObjectWithID(pid:String):ObjectBase{
			for each(var cont:ContainerData in _containers){
				if(cont.oid == pid){
					return cont;
				}
			}
			for each(var obj:ObjectData in _objects){
				if(obj.oid == pid){
					return obj;
				}
			}
			return null;
		}
		public function retrieveObject(pid:String):ObjectBase{
			return getObjectWithID(pid);
		}
		public function addContainerOnParent(xm:XML, pid:String):void{
			getObjectWithID(pid).addContainer(xm);
		}
		public function addObjectOnParent(xm:XML, pid:String):void{
			getObjectWithID(pid).addObject(xm);	
		}
		override protected function parse():void {
			super.parse();
		}
		public function get contents():Array {
			return _containers.concat(_objects);
		}
		
		
	}
	
	
}
internal class SingletonEnforcer {} 